﻿using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Web;

using OpenSMIL.Server.BingServices;
using System.Web.Script.Serialization;

namespace OpenSMIL.Server
{
    public partial class ValidateAddress : IHttpHandler
    {
        public bool IsReusable
        {
            get { throw new NotImplementedException(); }
        }

        JavaScriptSerializer jsonSerialiazer = new JavaScriptSerializer();

        public void ProcessRequest(HttpContext context)
        {
            string responseText = string.Empty;
            context.Response.ContentType = "application/json";
            if (!string.IsNullOrEmpty(context.Request.Params["Address"]))
            {
                string address = context.Request.Params["Address"];
                responseText = Address.ValidateAddress(address);
            }
            else
            {
                responseText = "missing input paratemer address";
                context.Response.StatusCode = 400; //give the callee feedback
            }
            var response = new {Accuracy = responseText};
            context.Response.Write(jsonSerialiazer.Serialize(response));
        }
    }
}
